package org.sean.framework.logstash.logging;

import ch.qos.logback.core.Layout;
import ch.qos.logback.core.encoder.EncoderBase;
import org.sean.framework.util.GSONUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * A KafkaMessageEncoder that can be configured with a {@link Layout} and creates
 * a serialized string for each event using the given layout.
 *
 * @param <E> E
 */
public class LogstashEncoder<E> extends EncoderBase<E> {

    private Layout<E> layout;

    public LogstashEncoder() {
    }

    public LogstashEncoder(Layout<E> layout) {
        this.layout = layout;
    }

    public Layout<E> getLayout() {
        return layout;
    }

    public void setLayout(Layout<E> layout) {
        this.layout = layout;
    }

    @Override
    public byte[] headerBytes() {
        return new byte[0];
    }

    @Override
    public byte[] encode(E event) {
        return layout.doLayout(event).getBytes();
    }

    @Override
    public byte[] footerBytes() {
        return new byte[0];
    }
}
